package com.oauth.google.client.ui.orkut;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.logical.shared.SelectionEvent;
import com.google.gwt.event.logical.shared.SelectionHandler;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.TabPanel;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;
import com.oauth.components.client.ui.gadgets.ProfileInfoPanel;
import com.oauth.google.client.beans.orkut.GoogleOrkutModel;
import com.oauth.google.client.beans.orkut.OrkutUser;
import com.oauth.google.client.rpc.orkut.OrkutRemoteServiceAsync;
import com.oauth.google.client.ui.orkut.handler.StatusUpdateHandler;
import com.oauth.google.client.ui.orkut.tabs.BirthdaysTab;
import com.oauth.google.client.ui.orkut.tabs.FriendsTab;
import com.oauth.google.client.ui.orkut.tabs.ScrapsTab;

public class HomePanel extends Composite {

	private static HomePanelUiBinder uiBinder = GWT.create(HomePanelUiBinder.class);

	interface HomePanelUiBinder extends UiBinder<Widget, HomePanel> {
	}

	private OrkutRemoteServiceAsync mService;
	private BirthdaysTab birthdayTab;
	private FriendsTab friendsTab;
	private ScrapsTab scrapsTab;

	@UiField
	HorizontalPanel hPanel1;

	@UiField
	ProfileInfoPanel profileInfoPanel;

	@UiField
	TabPanel tabPanel;

	public HomePanel() {
		initWidget(uiBinder.createAndBindUi(this));
		hPanel1.setCellHorizontalAlignment(profileInfoPanel, VerticalPanel.ALIGN_LEFT);
	}

	public void setService(OrkutRemoteServiceAsync pService) {
		mService = pService;
		profileInfoPanel.addValueChangeHandler(new StatusUpdateHandler(mService));
	}

	public void init() {
		birthdayTab = new BirthdaysTab(mService);
		friendsTab = new FriendsTab(mService);
		scrapsTab = new ScrapsTab(mService);

		tabPanel.add(birthdayTab, "Upcoming birthday's");
		tabPanel.add(scrapsTab, "Scraps");
		tabPanel.add(friendsTab, "My Friends");
		/*
		 * tabPanel.add(new VerticalPanel(), "My Communities"); tabPanel.add(new
		 * VerticalPanel(), "My Photos"); tabPanel.add(new VerticalPanel(),
		 * "My Videos"); tabPanel.add(new VerticalPanel(), "My updates");
		 */

		tabPanel.addSelectionHandler(new SelectionHandler<Integer>() {

			@Override
			public void onSelection(SelectionEvent<Integer> pEvent) {
				if (pEvent.getSelectedItem() == 0) {
					birthdayTab.init();
				} else if (pEvent.getSelectedItem() == 1) {
					scrapsTab.init();
				} else if (pEvent.getSelectedItem() == 2) {
					friendsTab.init();
				}/*
				 * else if(pEvent.getSelectedItem() == 3){
				 * communitiesTab.init(); }else if(pEvent.getSelectedItem() ==
				 * 4){ mGoogleOrkutPanel.initMainPanel(); }else{
				 * System.out.println
				 * ("Not seelceted:"+pEvent.getSelectedItem()); }
				 */
			}

		});
	}

	public void setData(GoogleOrkutModel pModel) {

		OrkutUser user = pModel.getUser();
		profileInfoPanel.setData(user.getThumbNailUrl(), user.getDisplayName(), user.getStatus());

	}

}
